include(FetchContent)
# 设置C++标准
set(CMAKE_CXX_STANDARD 11)

# 声明使用本地googletest源码

FetchContent_Declare(
  googletest
  SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/googletest-release-1.10.0
)
set(CMAKE_INSTALL_PREFIX "/" CACHE PATH "Installation prefix" FORCE)
# 对于Windows系统，确保使用共享CRT
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(googletest)

# 启用测试功能
enable_testing()

# 自定义安装规则，将googletest头文件安装到指定目录
if(NOT DISABLE_GTEST_INSTALL)
    install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/googletest-release-1.10.0/googlemock/include/gmock
            DESTINATION include/gtest
            COMPONENT gtest)
    
    install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/googletest-release-1.10.0/googletest/include/gtest
            DESTINATION include/gtest
            COMPONENT gtest)
            
    install(TARGETS gtest gtest_main gmock gmock_main
            LIBRARY DESTINATION lib
            ARCHIVE DESTINATION lib
            RUNTIME DESTINATION bin/gtest
            COMPONENT gtest)
            
    install(EXPORT GTestTargets
            FILE GTestConfig.cmake
            NAMESPACE GTest::
            DESTINATION lib/cmake/gtest
            COMPONENT gtest)
endif()

# 打印可用的目标，用于调试
# get_property(targets DIRECTORY PROPERTY BUILDSYSTEM_TARGETS)
# foreach(target IN LISTS targets)
#     message(STATUS "  Target: ${target}")
# endforeach()